package  com.example.Sao.Data;

import java.util.List;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.example.Sao.R;

public  class MListAdapter extends BaseAdapter{
	
	    List<BeanData> mListData;
	    Context  mContext;
	    public MListAdapter(Context  mContext, List<BeanData> mDatas) {
	    	this.mContext  = mContext;
	    	setList(mDatas);
		}
	    
	    public void setList( List<BeanData> mDatas){
	    	this.mListData = mDatas;
	    }

		@Override
		public int getCount() {
			return mListData.size();
		}
	
		@Override
		public Object getItem(int position) {
			return mListData.get(position);
		}
	
		@Override
		public long getItemId(int position) {
			return position;
		}
	
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			
			ViewHolder holder = null;
        	//Log.e("getView", "getView position = " + position);
			if( convertView == null){
				convertView	= LayoutInflater.from(mContext).inflate(R.layout.list_item_view, null);
				holder = new ViewHolder(); 
				holder.setmTextView((TextView)convertView.findViewById(R.id.mtView));
				holder.setmCheckBox((CheckBox)convertView.findViewById(R.id.mCheckbox));
				convertView.setTag(holder);
			}else{
				holder = (ViewHolder)convertView.getTag();
			}
			
			if(convertView != null){
				holder.getmTextView().setText(mListData.get(position).getmSymbName());
				if( mListData.get(position).isOpened()){
					holder.getmCheckBox().setChecked(true);
				}else{
					holder.getmCheckBox().setChecked(false);
				}
			}

			return convertView;
		}
	
	
	
}